﻿using Microsoft.Extensions.Options;
using System.Data;

namespace semantic_kernel_api.Extensions
{
    /// <summary>
    /// 基础过滤器扩展
    /// </summary>
    public static class BaseFilterExtensions
    {



        public static IServiceCollection AddAppsettingsInit(this IServiceCollection services)
        {

            IConfiguration Configuration;
            var config = new ConfigurationBuilder()
               .SetBasePath(Directory.GetCurrentDirectory())
               .AddJsonFile("appsettings.json", true, reloadOnChange: true);
            config.AddEnvironmentVariables();


            Configuration = config.Build();
            DatabaseCongif.configuration = Configuration; //设置数据库参数

            services.Configure<Dictionary<string,modelOptions>>(Configuration.GetSection("modelConfig"));

            var modelOptions = services.BuildServiceProvider().GetRequiredService<IOptions<Dictionary<string, modelOptions>>>().Value;
            DatabaseCongif.embeddingConfig = modelOptions["embedding"];
            DatabaseCongif.rerankConfig = modelOptions["rerank"];


            return services;
        }



    }
}
public static class DatabaseCongif
{
    private static IConfiguration _configuration = null;
    public static IConfiguration configuration
    {

        get { return _configuration; }

        set
        {
            _configuration = value;
        }

    }
    public static modelOptions embeddingConfig { get; set; }

    public static modelOptions rerankConfig { get; set; }
}

public class modelOptions
{ 
    public string endpoint { get; set; }
    public string apikey { get; set; }
    public string model { get; set; }
}



